package com.crawler.waf.security.authentication.bearer;

import javax.security.sasl.AuthenticationException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.core.annotation.Order;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import com.crawler.waf.security.authentication.PreAuthenticatedAuthenticationExtractor;

@Component
@Order(10)
public class PreAuthenticatedBearerTokenAuthenticationExtractor implements PreAuthenticatedAuthenticationExtractor {

    @Override
    public String getPrefix() {
        return "BEARER";
    }

    @Override
    public Authentication extractAuthentication(String authenticationValue, HttpServletRequest request) throws AuthenticationException {
        String bearerToken = authenticationValue.replace("\"", "").trim();
        return new PreAuthenticatedBearerTokenAuthentication(bearerToken);
    }
}
